import {getSession} from '@/utils/auth'
import {sectionRandom} from '@/utils'
import {userLogout} from '@/apis/login/LoginApi'

const state = {
  Log: [], //用户登录 0
  Offline: [],//用户下线 -1
  NotTested: [], //未测试 1 ，2
  wsDatas: null,
  appData: null,
  appStatusData: null,
  appBpskStatusData: null,
  appQpskStatusData: null,
}

const mutations = {
  webSocketMsg: (state, data) => {
    state.wsDatas = data
    switch (data.type) {
      case 0:
        state.Log = data
        break;
      case -1:
        state.Offline = data
        break;
      case 5:
        state.appData = data
        break;
      case 6:
        state.appStatusData = data
        break;
      case 7:
        state.appBpskStatusData = data
        break;
      case 8:
        state.appQpskStatusData = data
        break;
      default:
        //暂时默认未测试
        state.NotTested = data
        break;
    }
  },
  appInfoData: (state, data) => {
    state.appInfoData = data
  },
  fappId: (state, data) => {
    state.fappId = data
  },
}

const actions = {
  wsMsg({commit}, data) {
    return new Promise((resolve, reject) => {
      commit('webSocketMsg', data)
      resolve(data)
    })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}